<html>
<head><meta charset="utf-8"><title>Existential trait ref in rustc · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html">Existential trait ref in rustc</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219656153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219656153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219656153">(Dec 11 2020 at 20:13)</a>:</h4>
<p>Did some work on moving rustc's version to be more like Chalk.<br>
See <a href="https://github.com/rust-lang/rust/issues/79945">#79945</a><br>
<span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<a name="219871899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219871899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219871899">(Dec 14 2020 at 17:12)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I saw your comment on this PR (about how <code>skip_binder</code> is probably okay when sorting), but I realized I couldn't convince <em>myself</em> that was okay, because I had no clue why that's there and how there might be duplicate predicates. (And as such, whether eventually <code>^0.0</code> and <code>'^0.0</code> could be different.)</p>



<a name="219872061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219872061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219872061">(Dec 14 2020 at 17:13)</a>:</h4>
<p>When I first got around to that, my reasoning was "well, at this point, <code>Binder</code>s would have already been skipped somewhere, so it's okay to skip now". But that's not <em>really</em> the case (could have replaced with placeholders, for example).</p>



<a name="219872220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219872220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219872220">(Dec 14 2020 at 17:14)</a>:</h4>
<p>But anyways, that led me down the path of looking for why that was added in the first place and that was a rabbit hole. I think I've almost come up with an explanation for myself.</p>



<a name="219872608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219872608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219872608">(Dec 14 2020 at 17:17)</a>:</h4>
<p>But, I realized that the test that this was trying to fix is <em>really</em> fragile.</p>



<a name="219875170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219875170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219875170">(Dec 14 2020 at 17:36)</a>:</h4>
<p>isn't that trivially ok because we don't actually look at bound variables in <code>stable_cmp</code>?</p>



<a name="219875611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219875611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219875611">(Dec 14 2020 at 17:39)</a>:</h4>
<p>the implementation of <code>stable_cmp</code> does not care about anything apart from the relevant <code>DefId</code></p>



<a name="219875761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219875761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219875761">(Dec 14 2020 at 17:40)</a>:</h4>
<p>on that note, it might be nice to revive <a href="https://github.com/rust-lang/rust/issues/73815">#73815</a> <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="219876256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219876256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219876256">(Dec 14 2020 at 17:44)</a>:</h4>
<p>Well, that's a much easier thing to explain</p>



<a name="219876323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219876323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219876323">(Dec 14 2020 at 17:45)</a>:</h4>
<p>I am going to write that then defer "more interesting" explanations for <a href="https://github.com/rust-lang/rust/issues/73815">#73815</a> revival</p>



<a name="219876326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219876326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219876326">(Dec 14 2020 at 17:45)</a>:</h4>
<p>:P</p>



<a name="219877180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219877180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219877180">(Dec 14 2020 at 17:50)</a>:</h4>
<p>For a little bit longer idea of my thoughts here anyways: I think only <code>ExistentialProjection</code> predicates can be duplicated (not confirmed) and only when <code>dyn</code>. And from my experiments so far, I haven't actually been able to get late bound vars to appear there. Yes, GATs are a big potential source, but I haven't been able to get that to work yet.</p>



<a name="219877695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219877695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219877695">(Dec 14 2020 at 17:54)</a>:</h4>
<blockquote>
<p>And from my experiments so far, I haven't actually been able to get late bound vars to appear there.</p>
</blockquote>
<p>there == <code>ExistentialProjection</code> or am i misunderstanding something here</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Assoc</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="nc">dyn</span><span class="w">  </span><span class="k">for</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;'</span><span class="na">a</span><span class="p">,</span><span class="w"> </span><span class="n">Assoc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="p">()</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="219877961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219877961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219877961">(Dec 14 2020 at 17:57)</a>:</h4>
<p>Well, yes that's fine. The problem here is that the test uses a super trait with an associated type</p>



<a name="219878845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219878845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219878845">(Dec 14 2020 at 18:02)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ec6044f725936e3a18362574c9fa3340">This</a> is a little bit more minimized version of the test</p>



<a name="219878940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219878940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219878940">(Dec 14 2020 at 18:03)</a>:</h4>
<p>You'll find it's difficult (I haven't been able to get it) to inject a late bound var into the <code>dyn</code> in <code>main</code></p>



<a name="219879540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219879540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219879540">(Dec 14 2020 at 18:07)</a>:</h4>
<p>so something like <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=0103f8299105579d1b04fdc61c3ffea1">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=0103f8299105579d1b04fdc61c3ffea1</a> ?</p>



<a name="219879990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219879990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219879990">(Dec 14 2020 at 18:11)</a>:</h4>
<p>Hmm, that looks maybe like it works</p>



<a name="219880067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880067">(Dec 14 2020 at 18:11)</a>:</h4>
<p>(The fact that you get an error here says to me the current workaround doesn't work 100% of the time)</p>



<a name="219880086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880086">(Dec 14 2020 at 18:11)</a>:</h4>
<p>maybe</p>



<a name="219880181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880181">(Dec 14 2020 at 18:12)</a>:</h4>
<p>But, now, to extend this, we would have to find a way to inject a <em>second</em> late bound var, somewhere else</p>



<a name="219880308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880308">(Dec 14 2020 at 18:13)</a>:</h4>
<p>Just that <code>S = &amp;'a ()</code> and it <code>S = &amp;'b ()</code> are both predicates but come from <em>different</em> <code>for&lt;&gt;</code> (so that their binder indices are the same)</p>



<a name="219880520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880520">(Dec 14 2020 at 18:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232957">Jack Huey</span> <a href="#narrow/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc/near/219880067">said</a>:</p>
<blockquote>
<p>(The fact that you get an error here says to me the current workaround doesn't work 100% of the time)</p>
</blockquote>
<p>(The fact that you get an error here says to me that we should forbid specifying <code>S</code> here because it's already specified in the trait decl) <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="219880538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880538">(Dec 14 2020 at 18:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232957">Jack Huey</span> <a href="#narrow/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc/near/219880067">said</a>:</p>
<blockquote>
<p>(The fact that you get an error here says to me the current workaround doesn't work 100% of the time)</p>
</blockquote>
<p>See the note:</p>
<div class="codehilite"><pre><span></span><code>note: expected struct `Box&lt;dyn for&lt;&#39;a&gt; HttpService&lt;&#39;a, _, S = &amp;&#39;a (), S = _&gt;&gt;`
              found struct `Box&lt;dyn for&lt;&#39;a&gt; HttpService&lt;&#39;a, _, S = _&gt;&gt;`
</code></pre></div>
<p>Those two <em>should</em> unify fine</p>



<a name="219880792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880792">(Dec 14 2020 at 18:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc/near/219880520">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="232957">Jack Huey</span> <a href="#narrow/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc/near/219880067">said</a>:</p>
<blockquote>
<p>(The fact that you get an error here says to me the current workaround doesn't work 100% of the time)</p>
</blockquote>
<p>(The fact that you get an error here says to me that we should forbid specifying <code>S</code> here because it's already specified in the trait decl) <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>
</blockquote>
<p>Yeah, I thought about this. I'm not sure what the expected semantics are. Should you never be able to respecify? Only respecify when they are <em>compatible</em> (what if one is a subtype of another)? Or if you respecify, it completely ignores the super trait?</p>



<a name="219880848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880848">(Dec 14 2020 at 18:17)</a>:</h4>
<p>i would expect that you shouldn't be able to respecify at all</p>



<a name="219880942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219880942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219880942">(Dec 14 2020 at 18:18)</a>:</h4>
<p>if i had an infinite amount of time i would implement this and open a lang mcp for this</p>



<a name="219881005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881005">(Dec 14 2020 at 18:19)</a>:</h4>
<p>Currently, it seems like the second. But as we can see, it's not correct implementation, since both <code>_</code> and <code>&amp;'a ()</code> are technically <em>okay</em>, since we should eventually infer that <code>_ = &amp;'a ()</code>. But we "catch" that too early</p>



<a name="219881040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881040">(Dec 14 2020 at 18:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc/near/219880942">said</a>:</p>
<blockquote>
<p>if i had an infinite amount of time i would implement this and open a lang mcp for this</p>
</blockquote>
<p>Yeah, this is honestly a tricky case. (And also something definitely I feel like wg-traits should talk about)</p>



<a name="219881160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881160">(Dec 14 2020 at 18:20)</a>:</h4>
<p>I like to think that our Chalk work is a means to an end in terms of a better-defined Rust trait system</p>



<a name="219881237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881237">(Dec 14 2020 at 18:21)</a>:</h4>
<p>Which is evidenced by our discussion of everything from implied bounds, to <code>Alias</code>, etc. etc.</p>



<a name="219881256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881256">(Dec 14 2020 at 18:21)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error[E0308]: mismatched types
  --&gt; src/lib.rs:20:62
   |
20 |     let _: Box&lt;dyn for&lt;&#39;a&gt; HttpService&lt;&#39;a, _, S = &amp;&#39;a ()&gt;&gt; = make_server();
   |            -----------------------------------------------   ^^^^^^^^^^^^^ expected trait `HttpService&lt;RePlaceholder(Placeholder { universe: U1, name: BrNamed(DefId(0:17 ~ wtf[652d]::main::&#39;a), &#39;a) }), _#0t, S = &amp;RePlaceholder(Placeholder { universe: U1, name: BrNamed(DefId(0:17 ~ wtf[652d]::main::&#39;a), &#39;a) }) (), S = _#1t&gt;`, found trait `HttpService&lt;&#39;_#2r, _#2t, S = _#3t&gt;`
   |            |
   |            expected due to this
   |
   = note: expected struct `Box&lt;(dyn for&lt;&#39;a&gt; HttpService&lt;ReLateBound(DebruijnIndex(0), BrNamed(DefId(0:17 ~ wtf[652d]::main::&#39;a), &#39;a)), _#0t, S = &amp;ReLateBound(DebruijnIndex(0), BrNamed(DefId(0:17 ~ wtf[652d]::main::&#39;a), &#39;a)) (), S = _#1t&gt; + &#39;_#0r)&gt;`
              found struct `Box&lt;(dyn for&lt;&#39;a&gt; HttpService&lt;ReLateBound(DebruijnIndex(0), BrNamed(DefId(0:15 ~ wtf[652d]::make_server::&#39;a), &#39;a)), _#2t, S = _#3t&gt; + &#39;_#1r)&gt;`
</code></pre></div>



<a name="219881606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881606">(Dec 14 2020 at 18:24)</a>:</h4>
<p>do we fail to unify <code>BrNamed(DefId(0:17 ~ wtf[652d]::main::'a)</code> with <code>BrNamed(DefId(0:15 ~ wtf[652d]::make_server::'a)</code>?</p>



<a name="219881637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881637">(Dec 14 2020 at 18:24)</a>:</h4>
<p>i don't think so</p>



<a name="219881957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881957">(Dec 14 2020 at 18:26)</a>:</h4>
<p>ah, we use <code>dedup</code> instead of <code>dedup_by</code> in <code>relate</code> rn</p>



<a name="219881965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219881965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219881965">(Dec 14 2020 at 18:26)</a>:</h4>
<p>that's why this currently fails</p>



<a name="219882011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882011">(Dec 14 2020 at 18:27)</a>:</h4>
<p><code>dedup_by</code> using what as key?</p>



<a name="219882023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882023">(Dec 14 2020 at 18:27)</a>:</h4>
<p><code>stable_cmp</code></p>



<a name="219882056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882056">(Dec 14 2020 at 18:27)</a>:</h4>
<p>Hmm</p>



<a name="219882079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882079">(Dec 14 2020 at 18:27)</a>:</h4>
<p>this is what i do eagerly in <a href="https://github.com/rust-lang/rust/issues/73815">#73815</a></p>



<a name="219882131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882131">(Dec 14 2020 at 18:28)</a>:</h4>
<p>Yes, I saw</p>



<a name="219882183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882183">(Dec 14 2020 at 18:28)</a>:</h4>
<p>but because there are ways to have multiple <code>ProjectionPredicate</code> for identical assoc items we were uncomfortable with landing that change</p>



<a name="219882195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882195">(Dec 14 2020 at 18:28)</a>:</h4>
<p>The problem is I think that <code>dedup_by</code> with <code>stable_cmp</code>is only okay if we compare actual traits</p>



<a name="219882216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882216">(Dec 14 2020 at 18:28)</a>:</h4>
<p>(which you do in that PR but not currently)</p>



<a name="219882685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882685">(Dec 14 2020 at 18:32)</a>:</h4>
<p>uh, actually, would <code>dedup_by</code> with <code>stable_cmp</code> even fix this?</p>



<a name="219882763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219882763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219882763">(Dec 14 2020 at 18:33)</a>:</h4>
<p>I don't think so? Since <code>_#1t</code> here is an infer type. So it won't be deduped with <code>&amp;'a ()</code>. And so they will have a different number of predicates and fail to relate</p>



<a name="219891254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219891254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219891254">(Dec 14 2020 at 19:33)</a>:</h4>
<p>Actually, yeah. Because <code>stable_cmp</code> only cares about <code>S = ...</code>. Which is scary because which <code>S = ...</code> is <em>first</em> is the one that is used</p>



<a name="219905687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Existential%20trait%20ref%20in%20rustc/near/219905687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Existential.20trait.20ref.20in.20rustc.html#219905687">(Dec 14 2020 at 21:38)</a>:</h4>
<p>yeah, exactly <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>